package com.mc.algorithm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Foo {
	
	public void execute(){
		Scanner sc = new Scanner(System.in);
		StringBuilder str = new StringBuilder(sc.next());
		UF uf = new UF(str.length());
		int num = sc.nextInt();
		for(int i=0;i<num;i++){
			int p = sc.nextInt();
			int q = sc.nextInt();
			System.out.println(123);
			uf.union(p, q);
		}
		
		for(int i=0;i<str.length();i++){
			if(uf.data[i]==i)
				continue;
			List<Integer> list = new ArrayList<Integer>();
			while(uf.data[i]!=i){
				list.add(i);
				i = uf.data[i];
			}
			//最后一个节点
			list.add(i);
			
			char[] temp = new char[list.size()];
			for(int j=0;j<list.size();j++){
				temp[j]=str.charAt(list.get(j));
			}
			Arrays.sort(temp);
			for(int k=0;k<list.size();k++){
				str.setCharAt(list.get(k), temp[k]);
			}
		}
		System.out.println(str.toString());
	}
	
	static class UF{
		public int[] data;
		public UF(int n){
			data = new int[n];
			for(int i=0;i<n;i++)
				data[i]=i;
		}
		public int find(int p){
			while(data[p]!=p){
				p = data[p];
			}
			return p;
		}
		public void union(int p,int q){
			if(connected(p, q))
				return;
			int index = find(p);
			data[index]=find(q);
		}
		public boolean connected(int p,int q){
			return find(p)==find(q);
		}
	}
	
	public static void main(String[] args) {
		Foo f = new Foo();
		f.execute();
	}
}
